#include <lcir/IR/Constant.h>
#include <lcir/IR/Expression.h>
#include <lcir/IR/Op.h>
#include <lcir/IR/Prototype.h>
#include <lcir/IR/Value.h>

#include <vector>
namespace lcir {
std::vector<Prototype *> Op::deduceRetType(const std::vector<Value *> &operandVals) {
  auto protos = mapToVector<Prototype *>(operandVals, [](Value *val) { return val->getProto(); });
  return deduceRetType(protos);
}

bool Op::checkType(const std::vector<Value *> &operandVals) {
  auto protos = mapToVector<Prototype *>(operandVals, [](Value *val) { return val->getProto(); });

  return checkType(protos);
}
Constant *Op::tryFold(const std::vector<Value *> &operands) {
  std::vector<Constant *> constOperands;
  for (auto val : operands) {
    auto constVal = val->dyn_cast<Constant>();
    if (!constVal) return nullptr;
    constOperands.push_back(constVal);
  }
  return this->fold(constOperands);
}
std::vector<Operand *> Op::getOperands() const { return expr->getOperands(); }
std::vector<Value *> Op::getOperandValues() const { return expr->getOperandValues(); }
std::vector<Value *> Op::getResults() const { return expr->getResults(); }
Value *Op::getResult() const { return expr->getResult(); }

}  // namespace lcir